<?php
namespace app\models;

use yii\db\ActiveRecord;
use Yii;

class say extends ActiveRecord{
      public static function tableName(){
          return "{{%say}}";
        }
    
      public function rules(){
          return[
            ['openid','required','message' => '不能为空'],
            ['topic','required','message' => '问题不能为空'],
            ['answer','required','message' => '答案不能为空'],
            ['contact','required','message' =>'联系方式不能为空'],
        ];
     }
        
     public function add($data){
           if($data){
            $this->openid = $data['openId'];
            $this->topic = $data['topic'];
            $this->answer = $data['answer'];
            $this->contact = $data['contact'];
            $result = $this->save();
            if($result){
		  $error = 0;
		  return $error ;
	    }else{
		   $error = $this->getErrors();
		   return $error;
	    }
	    }else{
		   $error = 2;
		   return $error;
		}
       }
} 
